<!-- 企业认证列表 -->
<template>
  <div class="company-authentication company-authentication-list">
    <el-editable v-loading='list.loading' :data="list.table" :columns="list.column" height="400px">
        <template slot="default-ops" slot-scope="scope">
          <el-button type="text" v-show="editShow(scope.row)" @click="edit(scope.row)">编辑&nbsp;&nbsp;</el-button>
          <el-button type="text" v-show="submitShow(scope.row)" @click="submit(scope.row)">提交&nbsp;&nbsp;</el-button>
          <el-button type="text" v-show="recallShow(scope.row)" @click="recall(scope.row)">撤回&nbsp;&nbsp;</el-button>
          <el-button type="text" v-show="checkShow(scope.row)" @click="check(scope.row)">查看&nbsp;&nbsp;</el-button>
          <el-button type="text" v-show="changeShow(scope.row)" @click="change(scope.row)">变更&nbsp;&nbsp;</el-button>
        </template>
    </el-editable>
  </div>
</template>
<script>
import ElEditable from '@components/el-editable/index.vue'
import { tableColumn } from './const'
import { companyNewListAuthCompanyBaseVO,cancelById,commitById } from '@api/auth_center_v1.js'
export default {
  name: 'CompanyAuthentication',
  components: {ElEditable},
  data() {
    return {
      list: {
        column: tableColumn,
        table: [],
        loading: false
      }
    }
  },
  created() {
    this.initGlobalBtn()
    this.getList()
  },

  methods: {
    // 3,4没有了
    /*
      editShow,编辑：5，2，4
      checkShow,查看：1，0，3
      submitShow,提交：5，
      recallShow,撤回：0，3
      changeShow,变更：1
    */
    editShow(row) {
      return [5,2,4].includes(row.approveStatusKey)
    },
    submitShow(row) {
      return [5].includes(row.approveStatusKey)
    },
    recallShow(row) {
      return [0,3].includes(row.approveStatusKey)
    },
    checkShow(row) {
      return [1,0,3].includes(row.approveStatusKey)
    },
    changeShow(row) {
      return [1].includes(row.approveStatusKey)
    },
    check(row) {
      this.$router.push({
        path: '/company/authentication/verify',
        query: {
          companyBaseHisId: row.companyBaseHisId,
          type: row.companyTypeKey,
          dtype: row.nextLevelTypeKey,
          status: 'check',
          pageStatus: 'check',
          approveStatusKey: row.approveStatusKey,
          userId: row.userId
        }
      });
    },
    edit(row) {
      this.$router.push({
        path: '/company/authentication/verify',
        query: {
          companyBaseHisId: row.companyBaseHisId,
          type: row.companyTypeKey,
          dtype: row.nextLevelTypeKey,
          status: 'edit',
          pageStatus: 'check',
          approveStatusKey: row.approveStatusKey,
          userId: row.userId
        }
      });
    },
    change(row) {
      this.$router.push({
        path: '/company/authentication/verify',
        query: {
          companyBaseHisId: row.companyBaseHisId,
          type: row.companyTypeKey,
          status: 'change',
          pageStatus: 'check',
          approveStatusKey: row.approveStatusKey,
          dtype: row.nextLevelTypeKey,
          userId: row.userId
        }
      });
    },
    submit(row) {
      this.$axios({
        method: 'get',
        url: `${commitById}/${row.companyBaseHisId}`
      }).then(res => {
        if(res.data.code === '0') {
          this.$message({
            type: 'success',
            message: '提交成功'
          })
          this.getList()
        }
      })
    },
    recall(row) {
      this.$axios({
        method: 'get',
        url: `${cancelById}/${row.companyBaseHisId}`
      }).then(res => {
        if(res.data.code === '0') {
          this.$message({
            type: 'success',
            message: '撤销成功'
          })
          this.getList()
        }
      })
    },
    initGlobalBtn() {
      let obj = {
        type: 'btn',
        arr: [
          {
            val: '新建',
            type: 'primary',
            handle: this.goCreateNew
          }
        ]
      }
      this.$store.commit('changeLayoutHandle', obj)
    },
    goCreateNew() {
      this.$router.push({
        path: '/company/authentication/select-classify'
      });
    },
    getList() {
      this.list.loading = true;
      this.$axios({
        method: 'get',
        url: companyNewListAuthCompanyBaseVO
      }).then(res => {
        this.list.table = res.data.payload.length > 0 ? res.data.payload : []
      }).catch(err => {
        this.list.table = []
      }).finally(() => {
        this.list.loading = false
      })
    }
  }
}
</script>
<style lang="less">
  .company-authentication{
    display: flex;
    flex-direction: column;
    .el-editable{
      flex: 1;
    }
  }
  .company-authentication-list{
    .el-table td:last-child .cell{
      display: flex;
      justify-content: flex-start;
      .el-button{
        display: contents;
        margin-right: 10px;
        padding-right: 10px;
      }
    }
  }
</style>
